﻿using System;
using System.ComponentModel;

namespace BingleMaps.Models
{
	public class NotifyPropertyChanged : INotifyPropertyChanged
	{
		public event PropertyChangedEventHandler PropertyChanged;

		protected virtual void RaisePropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		public void SetProperty<T>(ref T property, T value, string name)
		{
			SetProperty(ref property, value, name, (p1, p2) => Equals(p1, p2));
		}

		public void SetProperty<T>(ref T property, T value, string name, Func<T, T, bool> comparer)
		{
			if (comparer(property, value))
			{
				return;
			}
			property = value;
			RaisePropertyChanged(name);
		}
	}
}
